package com.example.weather;

import static android.widget.Toast.*;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MsgModelActivity extends AppCompatActivity {
    ListView lv;
    String []msg={"今日寒冷，多穿衣服！","今日有暴雨，不宜出门","今日有大风，少出门"};
    String ans;
    EditText searchEt;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_msg_model);
        initview();
    }
    public void initview(){
        lv=findViewById(R.id.model_lv);
        searchEt=findViewById(R.id.model_et);
        ArrayAdapter adapter=new ArrayAdapter<>(this,R.layout.item_model,msg);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int pos, long id) {
                Intent intent=getIntent();
                String message=intent.getStringExtra("msg")+"\n"+msg[pos];
                searchEt.setText(message);
                Intent inres=new Intent();
                inres.putExtra("msg",message);
                setResult(1,inres);
                finish();//关闭当前页面
            }
        });
        //System.out.println(ans);
    }
}